package com.kedou.sdk.utils;



//import com.hn669.sysdk.secret.Base64;



import com.kedou.sdk.secret.Base64;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AESTool {
    //密码
    private static final String key = "aVTJEXFtRW34wfkT";
    //iv偏移量
    private static final String iv = "qSDUgOQzOHNVIB5R";

    /**
     * 加密：对字符串进行加密，并返回十六进制字符串(hex)
     *
     * @param encryptStr 需要加密的字符串
     * @return 加密后的十六进制字符串(hex)
     */
    public static String encrypt(String encryptStr) {
        try {
            IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes("UTF-8"));
            SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7PADDING");
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivParameterSpec);

            byte[] encrypted = cipher.doFinal(encryptStr.getBytes());

            byte[] encode = Base64.encode(encrypted);
//            byte[] encode = Base64.encode(encrypted,Base64.DEFAULT);
//            encode = Base64.encode(encode);
            String string = new String(encode);
            return string;
            //     return byte2HexStr(encrypted);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;
    }


}
